home *** CD-ROM | disk | FTP | other *** search
/ .net 2002 March / DotNetMagazine-Issue107-Coverdisc-NET107-02-03-PCMac.bin / pc / PC Software / free_browsing / DavesQckSearchDbar3-14 / dqsd.exe / src / DQSDTools / MenuBuilder.h < prev    next >
C/C++ Source or Header  |  2002-07-08  |  3KB  |  107 lines

  1. // MenuBuilder.h : Declaration of the CMenuBuilder
  2.  
  3. #ifndef __MENUBUILDER_H_
  4. #define __MENUBUILDER_H_
  5.  
  6. #include "resource.h"       // main symbols
  7.  
  8. /////////////////////////////////////////////////////////////////////////////
  9. // CMenuBuilder
  10. class ATL_NO_VTABLE CMenuBuilder : 
  11.     public CComObjectRootEx<CComSingleThreadModel>,
  12.     public CComCoClass<CMenuBuilder, &CLSID_MenuBuilder>,
  13.     public IObjectWithSiteImpl<CMenuBuilder>,
  14.     public ISupportErrorInfoImpl<&IID_IMenuBuilder>,
  15.     public IObjectSafetyImpl<CMenuBuilder, INTERFACESAFE_FOR_UNTRUSTED_CALLER>,
  16.     public IDispatchImpl<IMenuBuilder, &IID_IMenuBuilder, &LIBID_DQSDTOOLSLib>
  17. {
  18. public:
  19.     CMenuBuilder() 
  20.     : m_nMenuItem( 0 )
  21.     , m_nHorizontalAlignment( EHorizontalAlignment::RIGHT )
  22.     {
  23.         m_hMain = ::CreatePopupMenu();
  24.  
  25.         ATLTRACE("CMenuBuilder - created\n");
  26.         m_hTrackerWnd = NULL;
  27.         m_hTooltipWnd = NULL;
  28.     }
  29.  
  30.     virtual ~CMenuBuilder()
  31.     {
  32.         if(m_hTrackerWnd != NULL)
  33.         {
  34.             DestroyWindow(m_hTrackerWnd);
  35.         }
  36.         if(m_hTooltipWnd != NULL)
  37.         {
  38.             DestroyWindow(m_hTooltipWnd);
  39.         }
  40.  
  41.         ATLTRACE("CMenuBuilder - destroyed\n");
  42.         ATLTRACE("DQSDTools: Lock count %d\n", _Module.GetLockCount());
  43.     }
  44.  
  45. DECLARE_REGISTRY_RESOURCEID(IDR_MENUBUILDER)
  46.  
  47. DECLARE_PROTECT_FINAL_CONSTRUCT()
  48.  
  49. BEGIN_COM_MAP(CMenuBuilder)
  50.     COM_INTERFACE_ENTRY(IMenuBuilder)
  51.     COM_INTERFACE_ENTRY(IDispatch)
  52.     COM_INTERFACE_ENTRY(ISupportErrorInfo)
  53.     COM_INTERFACE_ENTRY(IObjectWithSite)
  54.     COM_INTERFACE_ENTRY(IObjectSafety)
  55. END_COM_MAP()
  56.  
  57. public:
  58.     STDMETHOD(SetSite)(IUnknown* pUnkSite);
  59.  
  60. // IMenuBuilder
  61. public:
  62.     STDMETHOD(InitialiseTooltips)(long displayTimeMultiplier);
  63.     STDMETHOD(get_HorizontalAlignment)(/*[out, retval]*/ short *pVal);
  64.     STDMETHOD(put_HorizontalAlignment)(/*[in]*/ short newVal);
  65.     STDMETHOD(AppendSubMenu)(/*[in]*/ BSTR bstrName, VARIANT* pvParentMenu, /*[out,retval]*/ long* phmenu);
  66.     STDMETHOD(AppendMenuItem)(/*[in]*/ BSTR bstrItem, /*[in]*/ BSTR bstrKey, /*[in]*/ BSTR bstrToolTip, /*[in,optional]*/ VARIANT* pvhMenu);
  67.     STDMETHOD(AppendSeparator)(/*[in]*/ long hmenu);
  68.     STDMETHOD(Display)(LPDISPATCH pDispDocument, VARIANT* pbstrSelection);
  69.  
  70. // Implementation
  71. protected:
  72.     static LPCTSTR    DQSD_REG_KEY;
  73.     static LPCTSTR    DQSD_SEC_KEY;
  74.     HMENU            m_hMain;
  75.     int                m_nMenuItem;
  76.     std::map< int, std::string > m_mapKeys;
  77.     std::map< int, std::string > m_toolTips;
  78.     
  79.     UINT            m_nHorizontalAlignment;
  80.  
  81.     CComPtr<IHTMLWindow2> m_spIHTMLWindow2;
  82.     CComPtr<IHTMLDocument2> m_spIHTMLDoc2;
  83.  
  84.     UINT getHorizontalPosition();
  85.  
  86.     enum EHorizontalAlignment
  87.     {
  88.         CENTER,
  89.         LEFT,
  90.         RIGHT,
  91.     };
  92.  
  93. protected:
  94.     static LRESULT CALLBACK TrackerWndProc(
  95.     HWND hwnd,      // handle to window
  96.     UINT uMsg,      // message identifier
  97.     WPARAM wParam,  // first message parameter
  98.     LPARAM lParam   // second message parameter
  99.     );
  100.  
  101.     HWND            m_hTrackerWnd;
  102.     static HWND        m_hTooltipWnd;
  103.  
  104. };
  105.  
  106. #endif //__MENUBUILDER_H_
  107.